/*******************************************************************************
ViewManager.cpp

Notes:
*******************************************************************************/

#include "ViewManager.h"

// The view manager instance pointer
ViewManager* ViewManager::m_pInstance = NULL;

//	GetManager(void)
//		Gets the view manager instance
ViewManager* ViewManager::GetManager(void)
{
	// If our instance isn't crated yet...
	if(NULL == m_pInstance)
	{
		// ... create it
		m_pInstance = new ViewManager();
	} // if

	// Return the pointer to the instance
	return m_pInstance;
} // GetManager

//	~ViewManager(void)
//		Clean up after ourselves
ViewManager::~ViewManager(void)
{
	// If our instance was created, delete and set it the pointer to NULL
	if(NULL != m_pInstance)
	{
		delete m_pInstance;
		m_pInstance = NULL;
	} // if

	// Clear the list of views
	m_viewList.clear();
} // ~ViewManager

//	CreateView(EntityID entityID, EntityResource& entityData)
//		Creates a view and stores it
//			entityID - The ID of the associated entity
//			entityData - The data used to create the entity
void ViewManager::CreateView(EntityID entityID, EntityResource& entityData)
{
	// If the type the same as the PaddleView type...
	if(entityData.GetEntityType() == PaddleView::Type)
	{
		// ... create a new view and store it
		PaddleView* pView = new PaddleView(entityID, entityData);
		m_viewList.push_back(pView);
	} // if
	else if(entityData.GetEntityType() == LevelView::Type)
	{
		// ... create a new view and store it
		LevelView* pView = new LevelView(entityID, entityData);
		m_viewList.push_back(pView);
	} // else if
	else if(entityData.GetEntityType() == BallView::Type)
	{
		// ... create a new view and store it
		BallView* pView = new BallView(entityID, entityData);
		m_viewList.push_back(pView);
	} // elseif
} // CreateView

//	Render(sf::RenderWindow& window)
//		Cycle through the stored views and render each of them
//			window - The window to draw to
void ViewManager::Render(sf::RenderWindow& window)
{
	for(unsigned int level = 0; level < 10; level++)
	{
		// Cycle through the views
		for(unsigned int view = 0; view < m_viewList.size(); view++)
		{
			// If the view is on the level we're workign with ...
			if(m_viewList[view]->GetLevel() == level)
			{
				// ... render the view
				m_viewList[view]->Render(window);
			}
		} // for
	} // for
} // Render